﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.ContentManagement;
using Orchard;
using RaisingStudio.Razor.Services;
using Orchard.Localization;
using Orchard.Settings;
using Orchard.Security;
using System.Web.Mvc;

namespace RaisingStudio.Razor.Models
{
    public class RazorModel : IRazorModel
    {
        private IOrchardServices services;
        public IOrchardServices Services
        {
            get
            {
                return this.services;
            }
        }

        private Localizer t;
        public Localizer T
        {
            get
            {
                return this.t;
            }
        }

        private dynamic content;
        public dynamic Content
        {
            get
            {
                return this.content;
            }
        }

        public ContentItem ContentItem
        {
            get
            {
                return (ContentItem)this.content;
            }
        }

        private dynamic context;
        public dynamic Context
        {
            get
            {
                return this.context;
            }
        }

        public WorkContext WorkContext
        {
            get
            {
                return this.services.WorkContext;
            }
        }

        public HttpContextBase HttpContext
        {
            get
            {
                return this.services.WorkContext.HttpContext;
            }
        }

        public ISite CurrentSite
        {
            get
            {
                return this.services.WorkContext.CurrentSite;
            }
        }

        public IUser CurrentUser
        {
            get
            {
                return this.services.WorkContext.CurrentUser;
            }
        }

        public IContentManager ContentManager
        {
            get
            {               
                return this.services.ContentManager;
            }
        }
        

        public T As<T>() where T : IContent
        {
            return ContentItem.As<T>();
        }

        public T Resolve<T>()
        {
            return this.services.WorkContext.Resolve<T>();
        }


        public RazorModel(IOrchardServices services, Localizer t, dynamic content, dynamic context)
        {
            this.services = services;
            this.t = t;
            this.content = content;
            this.context = context;
        }
    }
}